<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport"
			content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../../css/common.css" media="all">

	</head>

	<style type="text/css">
		.layui-table th {
			position: relative;
			min-height: 20px;
			height: 35px;
			line-height: 20px;
			font-size: 14px;
			padding: 0px 0px;
		}

		.layui-table td {
			position: relative;
			min-height: 20px;
			height: 100%;
			line-height: 14px;
			font-size: 14px;
			padding: 0px 0px;
		}

		.layui-input,
		.layui-textarea {
			display: block;
			width: 100%;
			padding: 0px 0px;
			border: 0px;
		}
	</style>

	<body>
		<div class="layui-fluid">
			<div class="layui-row" id="view">
				<form class="layui-form test_edit" lay-filter="test_detail">
					<div class="layui-card">
						<div class="layui-form-item">
							<label class="layui-form-label">秒杀时间<span style="color:red">*</span></label>
							<div class="layui-input-inline">
								<input type="text" name="dates" lay-verify="required" placeholder="请选择"
									autocomplete="off" class="layui-input limited_name">
								<input type="hidden" name="seckill_id" lay-verify="required" placeholder=""
									autocomplete="off" class="layui-input seckill_id">
							</div>
							<div class="layui-form-mid layui-word-aux">
								<a href="Javascript:;" onclick="searchdata('market_id')">选择</a>
							</div>
						</div>
						<div class="layui-card-body">
							<table class="layui-table" id="testtable">
								<!--<table class="layui-table" lay-size="sm">-->
								<colgroup>
									<col>
									<col>
									<col>
									<col>
									<col>
								</colgroup>

								<thead>
									<tr>
										<th></th>
										<th style="width: 10%;">商品编号</th>
										<th style="width: 15%;">商品名</th>
										<!-- <th>成本价</th> -->
										<th>会员价</th>
										<th>原抵扣积分</th>
										<th>秒杀价</th>
										<!--<th>积分比例%</th>-->
										<th>积分使用</th>
										<th>抢购数量</th>
										<th>已抢购数量</th>
										<th>购买上限</th>
										<th>显示数量</th>
										<th>排序</th>
									</tr>
								</thead>

								<tbody id="temp">
									<tr>
										<td></td>
										<td style="width: 20%;">
											<div class="flex">
												<input class="layui-input layui-input-choose" onfocus="choosedata()"
													name="" value="" />
												<button type="button" class="layui-btn layui-btn-sm"
													onclick="choosedata()"><i
														class="layui-icon layui-icon-search"></i></button>
											</div>
										</td>
										<td style="width: 25%;"></td>
										<td></td>
										<td></td>
										<td></td>
										<td></td>
										<td></td>
										<td></td>
										<td></td>
										<!--<td></td>-->
										<td></td>
										<td></td>
									</tr>
								</tbody>
							</table>
						</div>
					</div>
					<div class="layui-form-item layui-layout-admin">
						<div class="layui-input-block">
							<div class="layui-footer" style="left: 0;">
								<button type="reset" class="layui-btn layui-btn-primary">重置</button>
								<button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
							</div>
						</div>
					</div>

				</form>
			</div>
		</div>
		<script src="../../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../../js/jquery.min.js"></script>
		<script src="../../../../js/jquery.jqprint-0.3.js"></script>
		<script src="../../../../js/common.js"></script>
		<script>
			var _data = {}

			function child(data, index) {
				$(" input[name=seckill_id]").val(data.seckill_id);
				$(" input[name=dates]").val(data.name);
				console.log(data)
			}
			layui.config({
				base: '../../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'form'], function() {
				var $ = layui.$,
					admin = layui.admin,
					form = layui.form;
				//监听提交
				form.on('submit(demo1)', function(data) {
					var data = data.field;
					_data = Object.assign(_data, data);
					var request_data = [];
					var testtable = document.getElementById('testtable');
					console.log(testtable.rows.length);
					var rows = testtable.rows;
					for (var i = 0; i < rows.length; i++) {
						var cells = rows[i].cells;
						var skuid = $(cells).find('input[name=skuid]').val(),
							price = $(cells).find('input[name=price]').val(),
							stock = $(cells).find('input[name=stock]').val(),
							sales = $(cells).find('input[name=sales]').val(),
							num = $(cells).find('input[name=num]').val(),


							score = $(cells).find('input[name=score]').val(),
							score_scale = $(cells).find('input[name=score_scale]').val(),

							top_count = $(cells).find('input[name=top_count]').val();
						oid = $(cells).find('input[name=oid]').val();
						if (skuid) {
							request_data.push({
								'skuid': skuid,
								'price': price,
								'stock': stock,
								'num': num,
								'score': score,
								'score_scale': score_scale,
								'top_count': top_count,
								'sales': sales,
								'oid': oid
							})
						}
					}

					_data.request_data = JSON.stringify(request_data)
					console.log(JSON.stringify(_data));
					layer.confirm('确定要提交数据？', function() {
						loading();
						if (_data.id) {
							//submitdata(server.limited_goods_add);
						} else {
							delete _data.id
							submitdata(server.seckill_goods_add);
						}
					}, function() {
						layer.msg('取消操作');
					});
					return false;
				});

				function submitdata(_url) {
					$.post(_url, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								layer.alert('操作成功', function() {
									parent.layer.closeAll();
									parent.layui.table.reload('test-table-operate');
								});
							} else {
								layer.closeAll('loading')
								layer.msg(res.msg);
							}
							closeloading();
						} else {
							closeloading();
							layer.msg('服务器连接错误');
						}
					});
				}

				window.getdata = function(data, name, id) {
					var html;
					var a = 1;
					for (var i = 0; i < data.length; i++) {
						html += '<tr>' +
							'<td>' + (a + i) + '</td>' +
							'<td><div class="flex"><input  class="layui-input"  name="skuid" value=' + data[i]
							.skuid + ' /></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="skuname" value=' + (data[i]
								.skuname ? data[i].skuname : "") + '></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="price_member" value=' + data[i]
							.price_member + ' /></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="score_old" lay-verify="required" value="' +
							(data[i].score ? data[i].score : '0') + '"/></div></td>' +

							'<td><div class="flex"><input  class="layui-input"  name="price" lay-verify="required" value="' +
							(data[i].limit_price ? data[i].limit_price : '') + '"/></div></td>' +
							//							'<td><div class="flex"><input  class="layui-input"  name="score_scale" lay-verify="required" /></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="score" lay-verify="required" /></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="stock" lay-verify="required" /></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="sales"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="top_count"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="num"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="oid" value=' + (a + i) +
							' /></div></td>' +
							'</tr>';
					}

					$('#temp').before(html)
				}

				window.choosedata = function() {
					layer.open({
						type: 2,
						title: '选择',
						shadeClose: false,
						shade: 0.5,
						maxmin: true, //开启最大化最小化按钮
						area: ['100%', '100%'],
						content: 'list.html',
						end: function() {},
						success: function() {}
					});
				}
				window.searchdata = function(type) {
					switch (type) {
						case 'skuid':
							layer.open({
								type: 2,
								title: '选择',
								shadeClose: false,
								shade: 0.5,
								maxmin: true, //开启最大化最小化按钮
								area: ['800px', '98%'],
								content: 'choose_skuid.html',
								end: function() {},
								success: function() {}
							});
							break;
						case 'market_id':
							layer.open({
								type: 2,
								title: '选择',
								shadeClose: false,
								shade: 0.5,
								maxmin: true, //开启最大化最小化按钮
								area: ['800px', '90%'],
								content: 'choose_limited.html',
								end: function() {},
								success: function() {}
							});
							break;
					}
				}

			});
			//			$(document).on("blur","input[name=score]",function(e){
			//				var tr = e.currentTarget.parentElement.parentElement.parentElement
			//				console.log(tr)				
			//				var market_price = $(tr).find("input[name=price]").val()
			//				var score = $(tr).find("input[name=score]").val()
			//				if (score> 0 && market_price>0) {
			//					var sumprice_member = Math.round(parseFloat(market_price) * 100) / 100
			//					var sumScore = Math.round(parseFloat(score) * 100) / 100 
			//					var sumScale = Math.round(parseFloat((sumScore/market_price).toFixed(2)) * 100)  
			//					$(tr).find("input[name=score_scale]").val(sumScale)
			//				}
			//			})
			//			
			//			$(document).on("blur","input[name=score_scale]",function(e){
			//				
			//				var tr = e.currentTarget.parentElement.parentElement.parentElement
			//				console.log(tr)				
			//				var market_price = $(tr).find("input[name=price]").val()
			//				var score_scale = $(tr).find("input[name=score_scale]").val()
			//				if (score_scale >0 &&  score_scale <=100 && market_price>0 ) {
			//					var sumScore = Math.round(parseFloat((market_price*score_scale).toFixed(2)) * 100) /10000
			//					$(tr).find("input[name=score]").val(sumScore)
			//				}
			//			})
		</script>
	</body>

</html>
